﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HMS_Hospital_Team2._6.DO;

namespace HMS_Hospital_Team2._6.DA
{
    class ChiTietHoaDonDA
    {
        // Hàm thêm mới hóa đơn 
        public static void LaphoadonDV_DA(string sMadichvu, string sMahoadon, string sTendichvu, Decimal iGiadichvu, bool blchontra)
        {
            using (HMSHospitalEntities laphoadon  = new HMSHospitalEntities())
            {
                ChiTietHoaDon cthd= new ChiTietHoaDon();
                cthd.MaDichVu = sMadichvu;
                cthd.MaHoaDon = sMahoadon;
                cthd.TenDichVu = sTendichvu;
                cthd.DonGia = iGiadichvu;
                cthd.ChonTra = blchontra;
                
                laphoadon.AddToChiTietHoaDons(cthd);
                laphoadon.SaveChanges();
            }
        }

        // Hàm thông tin load dịch vụ
        public static List<ChiTietHoaDonDO> LoaddsDichVu_DA(string smaBN)
        {
            List<ChiTietHoaDonDO> dsDichvu = new List<ChiTietHoaDonDO>();
            using (HMSHospitalEntities laphoadon = new HMSHospitalEntities())
            {
                var chitiethoadon = from cthd in laphoadon.ChiTietHoaDons
                                    where cthd.HoaDon.MaBenhNhan == smaBN && cthd.HoaDon.TrangThai == false
                                    select cthd;
                foreach(var row in chitiethoadon)
                {
                    ChiTietHoaDonDO chitiethd = new ChiTietHoaDonDO();
                    chitiethd.MaDichVu = row.MaDichVu;
                    chitiethd.MaHoaDon = row.MaHoaDon;
                    chitiethd.TenDichVu = row.TenDichVu;
                    chitiethd.IDonGia = row.DonGia;
                    chitiethd.ChonTra = row.ChonTra;

                    dsDichvu.Add(chitiethd);
                }
                return dsDichvu; 
            }
        }
    }
}
